const $api = require('./../../utils/request').API;
import Toast from '@vant/weapp/toast/toast'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    projectInfo:{},
    addType:'',
    loading:false,
    code:'',
    roomCode:'',
    projectId:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      roomCode:options.roomCode,
      code:wx.getStorageSync('gongHao'),
      projectId:options.project
    })
    this.getProjectInfo(options.project)
  },

  getProjectInfo(id){
    $api.getProjectInfo(id).then(res=>{
      this.setData({
        projectInfo:res.tProject
      })
    })
  }, 

  inputBind(e){
    this.setData({
      code:e.detail.value
    })
  },


  addZhongType(e){
    this.setData({
      addType:e.currentTarget.dataset.type
    })
  },

  onSubmit( e ){
      if(this.data.addType == ''){
        return wx.showToast({
          title:'请选择加钟数量',
          icon:'none'
        })
      }else if( this.data.code == '' ){ 
      return wx.showToast({
        title:'请输入员工工号',
        icon:'none'
      })
      }else{
        var params = {
          roomCode:this.data.roomCode,
          gongHao:wx.getStorageSync('gongHao'),
          tiaoPeiFangShi:6,
          jiaZhongShu:Number(this.data.addType),
          projectId:this.data.projectId
        }
        $api.tiaoPai(params).then(res=>{
          if( res.code == 200 ){
            wx.showToast({
              title: '加钟成功',
              icon:'success',
              duration:1500,
              success:()=>{
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1500);
              }
            })
          }else{
            wx.showToast({
              title: '加钟失败',
              icon:'error',
              duration:1500,
              success:()=>{
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1500);
              }
            })
          }
     
        })
      }
  },

  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})